package com.situ.day13;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Dianji {
	public static void main(String[] args) {
		JFrame jf = new JFrame();  //新建
		jf.setTitle("测试");		  //窗口名
		jf.setSize(600, 400);	//窗口
		jf.setLocation(500, 300);//位置从左上开始
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置默认退出操作
		jf.setVisible(true);//把窗口显示在屏幕上
//		jf.setResizable(false);//固定窗口大小，禁止拖拽
		
		//创建
		JPanel Panel = new JPanel();
		jf.add(Panel);
		
		//布局
		Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		//组件
		JTextField textField1 = new JTextField();
		textField1.setPreferredSize(new Dimension(100, 30));
		Panel.add(textField1);
		
//		JPanel jiaPanel = new JPanel();
		JLabel lable1 = new JLabel("+");
		lable1.setPreferredSize(new Dimension(50, 30));
		Panel.add(lable1);
//		Panel.add(jiaPanel);
		
		//文本框2
		JTextField textField2 = new JTextField();
		textField2.setPreferredSize(new Dimension(100, 30));
		Panel.add(textField2);
		//等号
		JButton button = new JButton(" = ");
		Panel.add(button);
		//label 结果
		JLabel resultLabel = new JLabel();
		Panel.add(resultLabel);
		//添加点击事件
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String num1 = textField1.getText();
				System.out.println(num1);
				String num2 = textField2.getText();
				System.out.println(num2);
				int result = Integer.parseInt(num1) + Integer.parseInt(num2);
				resultLabel.setText(Integer.toString(result));
			}
		});
		
		
	}
}
